﻿cmake_minimum_required(VERSION 3.5)
project(CommonLib)

# Source and header files
set(COMMON_HEAD
    AppConfig/appconfig.h
    IdGenerator/idgenerator.h
    protocol/protocol.h
    protocol/protocolBuilder.h
    protocol/protocolConverter.h
    protocol/protocolOption.h
    CipherUtils/cipherutils.h
    SyncManager/syncmanager.h
    ThreadPool/threadpool.h
    Router/router.h
    UserManager/usermanager.h
    FileManager/filemanager.h  # Added here for clarity
    Debug/DEBUG.hpp            # Assuming this is a header file
)

set(COMMON_SOURCES
    AppConfig/appconfig.cpp
    IdGenerator/idgenerator.cpp
    protocol/protocol.cpp
    protocol/protocolBuilder.cpp
    protocol/protocolConverter.cpp
    protocol/protocolOption.cpp
    CipherUtils/cipherutils.cpp
    SyncManager/syncmanager.cpp
    ThreadPool/threadpool.cpp
    Router/router.cpp
    UserManager/usermanager.cpp
    FileManager/filemanager.cpp # Added here to match header

)

# Create the library
add_library(common STATIC ${COMMON_SOURCES} ${COMMON_HEAD} nlohmann/json.hpp nlohmann/json_fwd.hpp)

if(WIN32)

# Find required packages
find_package(OpenSSL REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
find_package(SOCI CONFIG REQUIRED)

# Link with found packages
target_link_libraries(common OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(common unofficial::sqlite3::sqlite3)
target_link_libraries(common $<IF:$<TARGET_EXISTS:SOCI::soci_mysql>,SOCI::soci_mysql,SOCI::soci_mysql_static>)

elseif(UNIX)

# Find required packages
find_package(OpenSSL REQUIRED)

# Link with found packages
target_link_libraries(common OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(common sqlite3)

endif()



# No need for separate UNIX and WIN32 sections for linking since we're using CMake's find_package which handles platform specifics.
